﻿using System;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Itdavany.Utility;
using Itdavany.Data;
using Itdavany.Objects;
//using RollingKitty.Data.Design;
using RollingKitty.Objects;
using RollingKitty.Data;
//using XNAExtras;

namespace RollingKitty.Objects
{
    public class StatBox : Dialog
    {
        //StatBoxSkin skin;

        Button btn_ok;

        Texture2D backtexture;

        Font titlefont;
        Color titlecolor;
        Font font;
        Color fontcolor;
        Font smallfont;

        PlayData playdata;

        //public string StatusString, AppraisalString;
        string statstr ="";
        public string StatusString
        {
            get
            {
                return statstr;
            }

            set {
                statstr = value;
            }
        }

        string apprstr = "";
        public string AppraisalString
        {
            get
            {
                return apprstr;
            }

            set
            {
                apprstr = value;
            }
        }


        TextPanel tx_desc;
        TextPanel tx_stat;
        TextPanel tx_appr;
        //TextPanel tx_stat


        /*public StatBox(StatBoxSkin skin)        // 스킨, 상태스트링, 평가스트링
        {
            playdata = (PlayData)Shared.GlobalBackstageGroup["playdata"];

            this.skin = skin;

            btn_ok = new Button(((SkinData)Shared.GlobalBackstageGroup["skin"]).Button[skin.normbutton_skin]);
            //btn_ok.ButtonText = "확인";
            btn_ok.LeftClicked += new EventHandler(this.OnOK);

            //btn_ok.X = 100 + X;
            //btn_ok.Y = 300 + Y;

            GameObjectGroup btngrp = new GameObjectGroup();
            btngrp.Add("btn_ok", btn_ok);

            SubScene.Add(btngrp);

            titlefont = SharedFont.Load(skin.titlefont);
            font = SharedFont.Load(skin.font);
            smallfont = SharedFont.Load(skin.smallfont);
            titlecolor = skin.titlecolor;            
            fontcolor = skin.fontcolor;

            backtexture = Shared.ContentManager.Load<Texture2D>(skin.texture);

            Width = backtexture.Width;
            Height = backtexture.Height;


        }*/

        public void UpdateStat() {
            tx_desc.Text = string.Format(
            "나이: {0}\n피로: {1}\n건강: {2}\n애정: {3}\n스트레스: {4}\n배부름: {5}\n목마름 : {8}\n거만함: {6}\n내가 지닌 돈: {7}", playdata.Cat.Age, playdata.Cat.CatStats.fatigue, playdata.Cat.CatStats.health,
                    playdata.Cat.CatStats.love, playdata.Cat.CatStats.stress, playdata.Cat.CatStats.stuffedness,
                    playdata.Cat.CatStats.arrogancy, playdata.Cat.CatStats.cash, playdata.Cat.CatStats.thirst);
            tx_stat.Text = statstr;
            tx_appr.Text = apprstr;
        }

        public StatBox(FrameArray frms)
            : base(frms)
        {

            playdata = (PlayData)Shared.GlobalBackstageGroup["playdata"];
            //frms
            tx_desc = (TextPanel)frms.FindObject("tx_desc");
            tx_stat = (TextPanel)frms.FindObject("tx_stat");
            tx_appr = (TextPanel)frms.FindObject("tx_appr");


            StatusString = "";
            AppraisalString = "";
        }


        public override void Arrange()
        {
            btn_ok.X = this.X + (this.Width - btn_ok.Width) / 2 - 10;
            btn_ok.Y = this.Y + this.Height - btn_ok.Height - 40;

            base.Arrange();
        }


        public override void Draw()
        {            
            /*Vector2 uledge = new Vector2(X, Y);
            Vector2 titlepos = uledge;
            Vector2 bodypos = uledge;

            titlepos.X += titlefont.MeasureString("상태") + 70;
            titlepos.Y += 10;

            bodypos.X += 30;
            bodypos.Y = titlepos.Y + titlefont.LineHeight + 20;

            DefaultSpriteBatch.Begin();
            DefaultSpriteBatch.Draw(backtexture, uledge, Color.White);

            titlefont.SpriteBatchOverride(DefaultSpriteBatch);
            font.SpriteBatchOverride(DefaultSpriteBatch);
            
            titlefont.DrawString(titlepos, titlecolor, "상태");

            font.TextBox(new Rectangle((int)bodypos.X, (int)bodypos.Y, 250, 450), fontcolor,
                "나이: {0}\n피로: {1}\n건강: {2}\n애정: {3}\n스트레스: {4}\n배부름: {5}\n거만함: {6}\n\n내가 지닌 돈: {7}\n\n"
                    + AppraisalString, playdata.Cat.Age, playdata.Cat.CatStats.fatigue, playdata.Cat.CatStats.health,
                    playdata.Cat.CatStats.love, playdata.Cat.CatStats.stress, playdata.Cat.CatStats.stuffedness,
                    playdata.Cat.CatStats.arrogancy, playdata.Cat.CatStats.cash);*/
            /*
            font.DrawString(bodypos, fontcolor, "나이: {0}", playdata.Cat.Age);

            bodypos.Y += font.LineHeight;

            font.DrawString(bodypos, fontcolor, "피로: {0}", playdata.Cat.CatStats.fatigue);

            bodypos.Y += font.LineHeight;

            font.DrawString(bodypos, fontcolor, "건강: {0}", playdata.Cat.CatStats.health);

            bodypos.Y += font.LineHeight;

            font.DrawString(bodypos, fontcolor, "애정: {0}", playdata.Cat.CatStats.love);

            bodypos.Y += font.LineHeight;

            font.DrawString(bodypos, fontcolor, "스트레스: {0}", playdata.Cat.CatStats.stress);

            bodypos.Y += font.LineHeight;

            font.DrawString(bodypos, fontcolor, "배부름: {0}", playdata.Cat.CatStats.stuffedness);

            bodypos.Y += font.LineHeight;

            font.DrawString(bodypos, fontcolor, "반항: {0}", playdata.Cat.CatStats.arrogancy);

            bodypos.Y += font.LineHeight * 2;

            font.DrawString(bodypos, fontcolor, StatusString);

            bodypos.Y += font.LineHeight * 2;

            foreach (string str in AppraisalString.Split('\n'))
            {
                smallfont.DrawString(bodypos, fontcolor, str);
                bodypos.Y += font.LineHeight;
            }

            titlefont.SpriteBatchOverride(null);
            font.SpriteBatchOverride(null);

            DefaultSpriteBatch.End();*/

            base.Draw();
        }
    }
}
